<?php

namespace App\Admin\Extensions;

use App\Model\Moment;
use Encore\Admin\Admin;

class MomentOp extends BaseAction
{
    protected function render()
    {
        Admin::script($this->script($this->actionUrl));
        $badbtn = $this->buildButton('fail', '违规处理', ['id' => $this->id, 'status' => Moment::STATUS_BAD]);
        $okbtn = $this->buildButton('ok', '正常通过', ['id' => $this->id, 'status' => Moment::STATUS_OK]);
        $delbtn = $this->buildButton('fail', '删除', ['id' => $this->id, 'status' => Moment::STATUS_DEL]);
        $topbtn = $this->buildButton('ok', '置顶', ['id' => $this->id, 'status' => 1, 'action' => 'top']);
        $unTopbtn = $this->buildButton('fail', '取消置顶', ['id' => $this->id, 'status' => 0, 'action' => 'top']);
        $str = [''];
        if ($this->row->status == Moment::STATUS_OK) {
            $str  = [$badbtn, $delbtn];
        } elseif ($this->row->status == Moment::STATUS_VERIFING) {
            $str  = [$okbtn, $badbtn, $delbtn];
        } elseif ($this->row->status == Moment::STATUS_BAD) {
            $str  = [$okbtn, $delbtn];
        }
        if ($this->row->is_top == 0) $str[] = $topbtn;
        else $str[] = $unTopbtn;
        return implode('<br/><br/>', $str);
    }
}
